<template>
    <van-nav-bar :title="title" :right-text="rightText" left-arrow @click-right="onClickRight" @click-left="onClickLeft"
        fixed />
</template>

<script setup lang="ts">
import router from '@/router'
//接受父组件传递的数据
const props = defineProps<{
    title?: string
    rightText?: string
    back?: () => void
}>()
//子组件向父组件传递
const emit = defineEmits<{
    'click-right': []
}>()
//点击文字触发
const onClickRight = () => {
    emit('click-right')

    //当前路径
    //     if (window.location.pathname === '/register') {
    //         router.push('/login')
    //     } else {
    //         router.push('/register')
    //     }
}

const onClickLeft = () => {
    if (props.back) {
        return props.back()
    }
    if (history.state.back) {
        router.back()
    } else {
        router.push('/')
    }
}

</script>

<style scoped lang="scss">
:deep() {
    .van-nav-bar {
        &__arrow {
            font-size: 18px;
            color: var(--cp-text1);
        }

        &__text {
            font-size: 15px;
        }
    }
}
</style>